<?php

include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';
/* remover atributo type */
class Refactoring_Tags_Link_Script extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";
      $mount_tree = new Mount_DOM_tree();

      $search = $domDocument->getElementsByTagName('link');

      foreach ($search as $f) {
         if ( !empty($f->getAttribute('type')) ) {
            $answer = ' type="'.$f->getAttribute('type').'"';
            $removeAtt = array ("type");
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer, "Não é mais necessário o atributo ", "remover o atributo <em>type</em>");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "$f->nodeName", 1, "", $removeAtt));
         }
      }

      $search = $domDocument->getElementsByTagName('script');

      foreach ($search as $f) {
         if ( !empty($f->getAttribute('type')) ) {
            $answer = ' type="'.$f->getAttribute('type').'"';
            $removeAtt = array ("type");
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer, "Não é mais necessário o atributo ", "remover o atributo <em>type</em>");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "$f->nodeName", 1, "", $removeAtt));
         }
      }
      
      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Resumir as tags &LT;link&GT; e &LT;script&GT;") . $result;
      }
      return $result;
   }

}

?>